
//389 - 找不同
class Solution {
    public char findTheDifference(String s, String t) {
        int[] a = new int[26];
        int[] b = new int[26];
        for(int i = 0; i < t.length(); i++){
            if(i < s.length()){
                a[s.charAt(i)-'a']++;
            }
            b[t.charAt(i)-'a']++;
        }
        for(int i = 0; i < t.length(); i++){
            if( a[t.charAt(i)-'a'] != b[t.charAt(i)-'a']){
                return t.charAt(i);
            }
        }
        return 'a';
    }
}
//387 - 字符串中第一个唯一字符
class Solution {
    public int firstUniqChar(String s) {
        int[] ch = new int[26];
        for(int i = 0; i < s.length(); i++){
            ch[s.charAt(i)-'a']++;
        }
        for(int i = 0; i < s.length(); i++){
            if(ch[s.charAt(i)-'a'] == 1){
                return s.indexOf(s.charAt(i));
            }
        }
        return -1;
    }
}
//67 - 二进制求和
class Solution {
    public String addBinary(String a, String b) {
        StringBuilder ans = new StringBuilder();
        int ca = 0;
        for(int i = a.length() - 1, j = b.length() - 1;i >= 0 || j >= 0; i--, j--) {
            int sum = ca;
            sum += i >= 0 ? a.charAt(i) - '0' : 0;
            sum += j >= 0 ? b.charAt(j) - '0' : 0;
            ans.append(sum % 2);
            ca = sum / 2;
        }
        ans.append(ca == 1 ? ca : "");
        return ans.reverse().toString();
    }
}

public class Test {
}
